﻿Imports System.Data.OleDb
Imports DTO
Public Class PhieuMuonSachDAO
    Public Function LayDSPhieuMuonTheoDocGia(ByVal ma As Integer) As List(Of Integer)
        DataProvider.OpenConnecttion()
        Dim sql As String = "select ctpms.MaSach FROM PHIEUMUONSACH pms , CHITIETPHIEUMUONSACH ctpms "
        sql = sql & " WHERE pms.MaChiTietPhieuMuon = ctpms.MaChiTietPhieuMuonSach and pms.MaDocgia = " & ma.ToString()
        Dim reader As OleDbDataReader
        reader = DataProvider.ExecSelect(sql)

        Dim dsSach As New List(Of Integer)
        While reader.Read()
            dsSach.Add(reader.GetInt32(0))
        End While
        DataProvider.CloseConnect()

        Return dsSach
    End Function

    Public Function ThemPhieuMuonSach(ByVal sql As String) As Integer
        DataProvider.OpenConnecttion()
        Dim kq As Integer = DataProvider.ExecInsert(sql)
        DataProvider.CloseConnect()
        Return kq
    End Function

    Public Function LayDanhSachPhieuMuonSach() As List(Of PhieuMuonSachDTO)
        DataProvider.OpenConnecttion()
        Dim dsPMS As New List(Of PhieuMuonSachDTO)
        Dim sql As String = "select MaPhieuMuon , NgayMuon , MaDocGia , MaChiTietPhieuMuon "
        sql = sql & "from PHIEUMUONSACH"
        Dim reader As OleDbDataReader
        reader = DataProvider.ExecSelect(sql)

        While reader.Read()
            Dim pms As New PhieuMuonSachDTO()
            pms.MaPhieuMuon = reader.GetInt32(0)
            pms.NgayMuon = reader.GetDateTime(1)
            pms.MaDocGia = reader.GetInt32(2)
            pms.MaChiTietPhieuMuon = reader.GetInt32(3)
            dsPMS.Add(pms)
        End While
        DataProvider.CloseConnect()
        Return dsPMS
    End Function
End Class
